package com.lxf.complayTest.controller;

import com.alibaba.fastjson2.JSONObject;
import com.lxf.complayTest.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Luoxingfa on 2023/2/28 0028 17:45
 */
@Controller
@CrossOrigin  //跨域
@Slf4j
@RequestMapping("/complay")
public class UserController {

    @Resource
    UserService userService;


    /**
     * 新增人员信息
     * @param json
     * @param request 用来解析签名验证
     * @return
     */
    @RequestMapping("/addUser")
    @ResponseBody
    public JSONObject addUser(@RequestBody JSONObject json,HttpServletRequest request){
        JSONObject js = userService.addUser(json,request);
        return js;
    }

    /**
     * 根据参数获取数据或获取全部数据
     * @param json
     * @param request 解析签名验证
     * @return
     */
    @RequestMapping("/getUser")
    @ResponseBody
    public JSONObject getUserList(@RequestBody JSONObject json, HttpServletRequest request){
        JSONObject js = userService.getUserList(json,request);
        return  js;
    }

    /**
     * 根据id修改信息
     * @param json
     * @param request
     * @return
     */
    @RequestMapping("/updateUser")
    @ResponseBody
    public JSONObject updateUserById(@RequestBody JSONObject json, HttpServletRequest request){
        JSONObject js = userService.updateUserById(json,request);
        return  js;
    }

    @RequestMapping("/rollBack")
    @ResponseBody
    public JSONObject rollBack(@RequestBody JSONObject json, HttpServletRequest request){
        JSONObject js = userService.rollBack(json,request);
        return  js;
    }
}
